﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TERP.WaterClient.Common;
using System.Data;
using CommonUtils;

namespace TERP.WaterClient.DbServices
{
    public class PriceService : BaseService
    {

		public PriceService()
            : base()
        {
        }

		public DataSet Its_Price_Get(
						  string strUnitCode
			)
		{
			string strTId = SystemGlobal.Instance.GetNextTid();
			//
			try
			{
				DataSet mdsFinal = new DataSet();
				mdsFinal = _dbService.Its_Price_Get(
						  _strGwUserCode,
						  _strGwPassword,
						  strTId,
						  _strSessionId
						 , strUnitCode
					  );
				mdsFinal = TERP.Utils.CUtils.MyDSDecode(mdsFinal);
				if (CMyDataSet.HasError(mdsFinal))
				{
					throw GenServiceException(mdsFinal);
				}
				return mdsFinal;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}


		public DataSet Its_Price_Update(
						  string strUnitCode
						 , string strDVTinh
						 , string strPrice
						 , string strDateUpdate
			)
		{
			string strTId = SystemGlobal.Instance.GetNextTid();
			//
			try
			{
				DataSet mdsFinal = new DataSet();
				mdsFinal = _dbService.Its_Price_Update(
						  _strGwUserCode,
						  _strGwPassword,
						  strTId,
						  _strSessionId
						 , strUnitCode
						 ,  strDVTinh
						 ,  strPrice
						 ,  strDateUpdate
					  );
				mdsFinal = TERP.Utils.CUtils.MyDSDecode(mdsFinal);
				if (CMyDataSet.HasError(mdsFinal))
				{
					throw GenServiceException(mdsFinal);
				}
				return mdsFinal;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}

		public void GetCurrentPrice()
		{
			DataTable dt_CurrentPrice = new DataTable();

			dt_CurrentPrice = Its_Price_Get(SystemGlobal.strUnitCodePriceBinh).Tables[DbTable.Tbl_Price];
			SystemGlobal.strPriceBinh = Convert.ToDouble(dt_CurrentPrice.Rows[0]["price"].ToString());

			SystemGlobal.strPriceCuocVo = Convert.ToDouble(Its_Price_Get(SystemGlobal.strUnitCodePriceCuocVo).Tables[DbTable.Tbl_Price].Rows[0]["price"].ToString());
			SystemGlobal.strPriceThung = Convert.ToDouble(Its_Price_Get(SystemGlobal.strUnitCodePriceThung).Tables[DbTable.Tbl_Price].Rows[0]["price"].ToString());
		}
    }

}
